<template>
  <el-container>
    <el-aside
      class="test-el-aside__main"
      width="265px"
    >
      <SideBar />
    </el-aside>
    <el-container>
      <el-header class="test-el-header__main">
        <div class="test-div__language">
          <el-dropdown @command="setLang">
            <span class="text-span__language">
              {{ $t('language') }}
              <el-icon class="text-el-icon__icon">
                <arrow-down />
              </el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item
                  v-for="(item, key) of messages"
                  :key="`dropdown${key}`"
                  :command="key"
                >{{ item.language }}</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
        <div class="test-div__sign-out">
          <el-icon>
            <SwitchButton />
          </el-icon>
        </div>
      </el-header>
      <el-main class="test-el-main__main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { defineComponent } from 'vue'
import { SwitchButton, ArrowDown } from '@element-plus/icons-vue'
import { useI18n } from 'vue-i18n'

import SideBar from '@/components/SideBar'
import messages from '@/lang/messages.js'

defineComponent({
  name: 'baseIndex'
})

const i18n = useI18n()

const setLang = (lang) => {
  i18n.locale.value = lang
}
</script>

<style lang="less" scoped>
.test-el-aside__main {
  background: #1e1e2d;
}

.test-el-header__main {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  box-shadow: 0px 10px 30px 0px rgba(82, 63, 105, 0.05);
  overflow: hidden;

  .test-div__language {
    display: flex;
    align-items: center;
    margin-right: 20px;

    .text-span__language {
      display: flex;
      align-items: center;
      cursor: pointer;
    }

    .text-el-icon__icon {
      margin-left: 5px;
    }
  }

  .test-div__sign-out {
    cursor: pointer;
  }
}

.test-el-main__main {
  background: #f5f8fa;
}
</style>